// pages/netCase/evidenceList/evidenceList.js
import ecfsConfig from '../../../config/ecfs.config.js'
import locale from '../../../config/locale/zh-CN/netCase/evidence.js'
import * as evidenceApi from '../../../api/evidence.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    locale,
    evidenceList: [],
    showAdd: true,
    caseId: ''
  },
  /**
   * 跳转添加证据材料的页面
   */
  addEvidence() {
    wx.navigateTo({
      url: '../evidenceInfo/evidenceInfo',
    })
  },
  editEvidence: function (e) {
    var evidenceid = e.currentTarget.dataset.evidenceid
    var certificatenumber = e.currentTarget.dataset.certificatenumber
    let that = this
    wx.request({
      url: ecfsConfig.IS_PRODUCTION ? (ecfsConfig.SERVER_DOMAIN + ecfsConfig.GET_USERINFO_URL) : (ecfsConfig.SERVER_DOMAIN + ecfsConfig.RAP_URL_PREFIX + ecfsConfig.GET_USERINFO_URL),
      method: 'POST',
      success: function (res) {
        if (certificatenumber === res.data.body.cardNum) {
          wx.navigateTo({
            url: '../evidenceInfo/evidenceInfo?evidenceid=' + evidenceid,
          })
        }
      },
      fail: function (res) {
        console.log(res.data);
        console.log('is failed')
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const config = {
      url: ecfsConfig.IS_PRODUCTION ? (ecfsConfig.SERVER_DOMAIN + ecfsConfig.EVIDENCE_LIST_URL) : (ecfsConfig.SERVER_DOMAIN + ecfsConfig.RAP_URL_PREFIX + ecfsConfig.EVIDENCE_LIST_URL),
      data: {
        caseId: '',
      },
    }
    evidenceApi.getAllEvidences(config).then(res => {
      this.setData({
        evidenceList: res.data[0].body.result
      })

    }).catch(error => {
      console.log(error)
      console.log('is failed')
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})